package dna;




import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFileChooser;


import core.gui.FileChooser;
import core.inputoutput.formatting.Format;
import core.main.Main;


public class DNAtoCGMain extends Main{

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		PDBparserDNA parser = new PDBparserDNA();
		DNAtoCGconverter conv = new DNAtoCGconverter(Format.DNA_COARSE_GRAIN);
		
		File INPUT = initializeGUI("DNA to Coarse Grain Converter", parser, conv);
		System.out.println("Running");
		
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(
					makeOutputFileName(INPUT)));
			out.write(conv.applyConverter(parser.parse(INPUT, Format.DNA_ATOMISTIC)));
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		myGUI.getOPpanel().print("Done!");
		
	}

	private static String makeOutputFileName(File input) {
		if (input.getName().contains("."))
			return input.getName().substring(0,input.getName().lastIndexOf(".")) + "_CG.pdb";
		return input +"out.pdb";
	}

}
